<template>
  <div>
    <el-dialog title="商户余额充值" append-to-body :close-on-click-modal="false" @close="closeDialog()" v-model="visible">
      <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
        label-width="110px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="商家名称" prop="name">
              <el-input v-model="dataForm.name" placeholder="至少输入2个字"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="telephone">
              <el-input v-model="dataForm.telephone" placeholder="商家地址长度不能超过100个字"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="商户余额" prop="balance">
              <el-input v-model="dataForm.balance" placeholder="请填写登入账号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商家地址" prop="address">
              <el-input v-model="dataForm.address" placeholder="商家地址"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="充值金额" prop="rechargeMoney">
              <el-input v-model="dataForm.rechargeMoney" placeholder="至少输入2个字"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="赠送金额" prop="giveMoney">
              <el-input v-model="dataForm.giveMoney" placeholder="请填写赠送金额"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="close()">取消</el-button>
          <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { addRechargeList, getObj } from '@/api/operate/merchant.js'
export default {
  data () {
    return {
      visible: false,
      dataForm: {},
      dataRule: {}
    }
  },
  methods: {
    init (id) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        getObj(id).then((response) => {
          console.log(response);
          this.dataForm = response.data.data
          this.dataForm.merchantId = response.data.data.id
          delete this.dataForm.id
        }).catch(() => { })

      })
    },
    dataFormSubmit () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          addRechargeList(this.dataForm).then(data => {
            this.$notify.success('添加成功')
            this.visible = false
            this.$emit('refreshDataList')
          })
        }
      })
    },
    close () { },
    closeDialog () { }
  },
}
</script>

<style>
</style>